package top.deepdesigner.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.deepdesigner.pojo.DtsGoodsProduct;
import top.deepdesigner.service.DtsGoodsProductService;

import java.util.Date;
import java.util.List;

/**
 * Start up <br/>
 * Created with IntelliJ IDEA. <br/>
 * Project Name: shop_manage <br/>
 * Author: duanruiqing <br/>
 * DateTime: 2022/9/20 星期二 20:20:54 <br/>
 */
@Service
public class DtsGoodsProductServiceImpl extends ServiceImpl<BaseMapper<DtsGoodsProduct>, DtsGoodsProduct> implements DtsGoodsProductService {
  @Override
  public Long getGoodsProductCount() {
    return this.count(null);
  }

  @Override
  public List<DtsGoodsProduct> getGoodsProductByGoodId(Long id) {
    LambdaQueryWrapper<DtsGoodsProduct> wrapper = new LambdaQueryWrapper<>();
    wrapper.eq(DtsGoodsProduct::getGoodsId, id)
        .eq(DtsGoodsProduct::getDeleted, false);
    return this.list(wrapper);
  }

  @Override
  @Transactional
  public void deleteGoodsProduct(Integer goodsId) {
    LambdaQueryWrapper<DtsGoodsProduct> wrapper = new LambdaQueryWrapper<>();
    wrapper.eq(DtsGoodsProduct::getGoodsId, goodsId);
    DtsGoodsProduct goodsProduct = new DtsGoodsProduct();
    goodsProduct.setDeleted(true);
    goodsProduct.setUpdateTime(new Date());
    this.update(goodsProduct, wrapper);
  }
}
